/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Admin;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author Tomcat
 */
public class CopyFile {

    public static File FileCopy(String srFile, String dtFile) {
        File f2 = new File(dtFile);
        try {
            long time = new Date().getTime();
            File f1 = new File(srFile);
            String extension = dtFile.substring(dtFile.indexOf("."));   //Get extension of File
            String fileName = dtFile.substring(0, dtFile.indexOf(".")); //Cut extension of File
            f2 = new File("IMG_" + time + extension);//File name + time = new file name
            InputStream in = new FileInputStream(f1);
            OutputStream out = new FileOutputStream(f2);
            byte[] buf = new byte[1024];
            int len = 0;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return f2;
    }
}
